package com.yvon.maple.service.msg.sub.controller;

import com.yvon.boot.common.result.ResponseData;
import com.yvon.maple.cloud.web.data.ApiController;
import com.yvon.maple.service.msg.sub.model.entity.SubscribeActive;
import com.yvon.maple.service.msg.sub.model.entity.SubscribePassive;
import com.yvon.maple.service.msg.sub.model.vo.SubscribeActiveVo;
import com.yvon.maple.service.msg.sub.model.vo.SubscribePassiveVo;
import com.yvon.maple.service.msg.sub.model.vo.SubscribeVo;
import com.yvon.maple.service.msg.sub.service.SubscribeActiveService;
import com.yvon.maple.service.msg.sub.service.SubscribePassiveService;
import com.yvon.maple.service.msg.sub.service.SubscribeSendService;
import com.yvon.maple.utils.DataConverter;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author : Yvon
 * @since : 2022-05-19
 */
@RestController
@RequestMapping(value = "/subscribes")
@Api(value = "订阅管理", tags = "消息服务 - 订阅管理API")
public class SubscribeController extends ApiController {

    @Resource
    private SubscribePassiveService passiveService;

    @Resource
    private SubscribeActiveService activeService;

    @Resource
    private SubscribeSendService sendService;

    @PutMapping("/active")
    @ApiOperation(value = "更新主动订阅", notes = "更新主动订阅API")
    public ResponseData<Boolean> updateActive(@RequestBody List<SubscribeActiveVo> voList) {
        List<SubscribeActive> activeList = DataConverter.convert(voList, SubscribeActive.class);
        return success(activeService.updateList(activeList));
    }

    @PutMapping("/send/active")
    @ApiOperation(value = "发送主动订阅消息", notes = "更新主动订阅API")
    public ResponseData<Boolean> sendActive(@RequestBody SubscribeVo subscribeVo) {
        return success(sendService.sendMsg(subscribeVo));
    }

    @PutMapping("/passive")
    @ApiOperation(value = "更新被动订阅", notes = "更新被动订阅API")
    public ResponseData<Boolean> updatePassive(@RequestBody List<SubscribePassiveVo> voList) {
        List<SubscribePassive> passiveList = DataConverter.convert(voList, SubscribePassive.class);
        return success(passiveService.updateList(passiveList));
    }


}
